package com.guigu.ababa.ababaclassroom.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.ababa.ababaclassroom.dao.Ab_userMapper;
import com.guigu.ababa.ababaclassroom.entity.Ab_user;
import com.guigu.ababa.ababaclassroom.handler.MD5;
import com.guigu.ababa.ababaclassroom.service.Ab_userService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;


//user用户servcie接口实现类
@Service
@Transactional//(事务注解)
public class Ab_userServiceImpl implements Ab_userService {

    @Autowired
    private Ab_userMapper ab_userMapper;

    @Autowired
    private MD5 md5;

    //添加user用户
    @Override
    public int insertuser(Ab_user ab_user) {
        return ab_userMapper.insert(ab_user);
    }

    //查询user全部用户
    @Override
    public List<Ab_user> selectlist() {
        return ab_userMapper.selectList(null);
    }

    //删除user用户假删除
    @Override
    public int update_deleuser(Ab_user ab_user) {
        return ab_userMapper.updateById(ab_user);
    }

    //修改user用户数据
    @Override
    public int updateuser(Ab_user ab_user) {
        return ab_userMapper.updateById(ab_user);
    }

    //根据条件查询user用户
    @Override
    public List<Ab_user> selectByBatchid(String name,String tname) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put(name,tname);
        List<Ab_user> ab_users = ab_userMapper.selectByMap(hashMap);
        return ab_users;
    }

    //分页查询user用户
    @Override
    public List<Ab_user> selectPage(int current,int size) {
        Page<Ab_user>page=new Page<>(current,size);
        IPage<Ab_user> ab_userIPage = ab_userMapper.selectPage(page, null);
        //总条数
        System.out.println(page.getTotal());
        //查询的数据条数
        System.out.println(page.getSize()+"jjjd");
        List<Ab_user> records = page.getRecords();
        System.out.println(records);
        return records;
    }

    //用户账号密码登陆
    @Override
    public Ab_user Selectlogin(Ab_user ab_user) {
        Ab_user selectlogin = ab_userMapper.Selectlogin(ab_user.getUsername(), md5.MD5(ab_user.getSalt()));
        return selectlogin;
    }

    //用户手机号登陆
    @Override
    public Ab_user Selectphonelogin(String phone) {
        return ab_userMapper.Selectphonelogin(phone);
    }

    @Override
    public Ab_user SelectoneName(String ab_username) {
        return ab_userMapper.SelectoneName(ab_username);
    }
}
